package cn.zhz.privacy.sensitive.handler;

import cn.hutool.core.util.StrUtil;
import cn.zhz.privacy.sensitive.SensitiveType;
import cn.zhz.privacy.sensitive.SensitiveTypeHandler;

/**
 * 手机号脱敏处理类
 * 18233583070 脱敏后: 182****3030
 * @author ;
 */
public class MobilePhoneSensitiveHandler implements SensitiveTypeHandler {
    @Override
    public SensitiveType getSensitiveType() {
        return SensitiveType.MOBILE;
    }

    @Override
    public String handle(Object src) {
        if(src==null){
            return null;
        }
        String value = src.toString();
        int len=value.length();
        if(len<=8){
            return value;
        }
        return StrUtil.subPre(value, 3)
                .concat( "****")
                .concat(StrUtil.subSufByLength(value, 4));
    }

}
